package com.cqc.flycotablayout01.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.cqc.flycotablayout01.PagerSlidingTab;
import com.cqc.flycotablayout01.R;
import com.cqc.flycotablayout01.adapter.MainFragAdapter;
import com.cqc.flycotablayout01.fragment.Frag1;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SlidingTabLayoutActivity extends AppCompatActivity {

    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.slidingTab)
    PagerSlidingTab slidingTabLayout;
    @BindView(R.id.tabLayout_1)
    SlidingTabLayout tabLayout1;
    @BindView(R.id.tabLayout_2)
    SlidingTabLayout tabLayout2;
    @BindView(R.id.tabLayout_3)
    SlidingTabLayout tabLayout3;
    @BindView(R.id.tabLayout_4)
    SlidingTabLayout tabLayout4;
    @BindView(R.id.tabLayout_5)
    SlidingTabLayout tabLayout5;

    private String[] titles = {"语文", "数学", "英语", "物理", "化学", "生物"};
    private ArrayList<Fragment> frags = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slding_tablayout);
        ButterKnife.bind(this);

//        MainPagerAdapter adapter = new MainPagerAdapter(titles);

        MainFragAdapter adapter = new MainFragAdapter(getSupportFragmentManager(), titles);
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(5);

        tabLayout1.setViewPager(viewPager);
        tabLayout2.setViewPager(viewPager);
        tabLayout3.setViewPager(viewPager);
        tabLayout4.setViewPager(viewPager);

        for (int i = 0; i < titles.length; i++) {
            frags.add(new Frag1());
        }
        tabLayout5.setViewPager(viewPager,titles,this,frags);

        //自定义的TabLayout
        slidingTabLayout.setViewPager(viewPager);
        slidingTabLayout.setFillViewport(true);

        tabLayout1.showDot(0);
        tabLayout2.showMsg(1, 5);
    }
}
